class Solution:
    def minSwaps(self, s: str) -> int:
        ans = 0
        now = 0
        for ch in s:
            if ch == "]":
                now -= 1
                if now < 0:
                    now += 2
                    ans += 1
            else:
                now += 1
        return ans


if __name__ == "__main__":
    print(Solution().minSwaps("][]["))  # 1
    print(Solution().minSwaps("]]][[["))  # 2
    print(Solution().minSwaps("[]"))  # 0
